<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.User"%>

<script type="text/javascript">
<!--
	$(document).ready(function() {
		$("#editGroupDiv").dialog({
			title : '<%=UserUtil.getCurrentMenuItemName() %>',
			width : 700,
			resizable : false,
			modal : true
		});
		
		$("#cancelEditGroupBtn").click(function() {
			$("#editGroupDiv").dialog("close");
		});
		
		$("#doDeleteGroupBtn").click(function() {
			var answer = confirm('是否確定刪除 ?');
        	
        	if (!answer)
        		return ;
        	
			var groupPk = $('#editGroup\\.groupPk').val();
							
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9007.action'/>",
				async : true,
				type : 'POST',
				data : {doDeleteGroup: 'doDeleteGroup', 'editGroup.groupPk': groupPk},
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {						
					$("#ajaxErrorMessageDiv").html(data);
					$("#ajaxErrorMessageDiv").dialog({
						title : '<%=UserUtil.getCurrentMenuItemName() %>',
						width : 300,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {								
								if (1==$("#doAjaxDeleteGroupResultCode").val()){
									doQueryAction();
								}
								$(this).dialog("close");
								
							}
						}
					});
					$("#editGroupDiv").dialog("close");
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
		});
		
		$("#doSaveGroupBtn").click(function() {
			var pk = $('#editGroup\\.groupPk').val();
			var groupNo = $('#editGroup\\.groupNo').val();
			var groupName = $('#editGroup\\.groupName').val();
			var groupType = $('#editGroup\\.groupType').val();
			var groupAddress = $('#editGroup\\.groupAddress').val();
			var contactName = $('#editGroup\\.contactName').val();
			var contactEmail = $('#editGroup\\.contactEmail').val();
			var contactTelNo = $('#editGroup\\.contactTelNo').val();
			var contactCellNo = $('#editGroup\\.contactCellNo').val();
			var groupNote = $('#editGroup\\.groupNote').val();
			var postAcct = $('#editGroup\\.postAcct').val();
			var mainBank = $('#editGroup\\.mainBank').val();
			var achEdiid =$('#editGroup\\.achEdiid').val();//add by jeff for ach
			
			var errMsg = "";
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號 是必要欄位<br/>";
			}
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}
			
			if (null == groupType || 0 == groupType.length){
				errMsg = errMsg + "業者類別 是必要欄位<br/>";
			}
			
			if (null == mainBank || 0 == mainBank.length){
				errMsg = errMsg + "主辦銀行 是必要欄位<br/>";
			}
			
			if (null == groupName || 0 == groupName.length){
				errMsg = errMsg + "業者名稱 是必要欄位<br/>";
			}
			
			if (null == groupAddress || 0 == groupAddress.length){
				errMsg = errMsg + "地址 是必要欄位<br/>";
			}
			
			if (null == contactName || 0 == contactName.length){
				errMsg = errMsg + "聯絡人 是必要欄位<br/>";
			}
			
			if (null == contactEmail || 0 == contactEmail.length){
				errMsg = errMsg + "E-MAIL 是必要欄位<br/>";
			}
			else if (! verifyEmail(contactEmail)){
				errMsg = errMsg + "E-MAIL 格式錯誤<br/>";
			}
			
			if (null == contactTelNo || 0 == contactTelNo.length){
				errMsg = errMsg + "電話號碼 是必要欄位<br/>";
			}
			//else if (isNaN(contactTelNo)){
			//	errMsg = errMsg + "電話號碼 格式錯誤<br/>";
			//}
			
			if (null == contactCellNo || 0 == contactCellNo.length){
				errMsg = errMsg + "手機號碼 是必要欄位<br/>";
			}
			//else if (isNaN(contactCellNo)){
			//	errMsg = errMsg + "手機號碼 格式錯誤<br/>";
			//}
			else if (10 != contactCellNo.length){
				errMsg = errMsg + "手機號碼  位數錯誤<br/>";
			}
			
			//有輸入ach再檢核
			if (achEdiid){
				if (4 == groupType){
					errMsg = errMsg + "業者類別為「車貸策略聯盟」，<br/>ACH業者代號 必需為空白。<br/>";
				}else{
					if (12 != achEdiid.length){
					errMsg = errMsg + "ACH業者代號 為固定長度12碼<br/>";
					}		
				}
			}
			
			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			
			
			$('#hidden\\.editGroup\\.groupPk').val(pk);
			$('#hidden\\.editGroup\\.groupNo').val(groupNo);
			$('#hidden\\.editGroup\\.groupType').val(groupType);
			$('#hidden\\.editGroup\\.groupName').val(groupName);
			$('#hidden\\.editGroup\\.mainBank').val(mainBank);
			$('#hidden\\.editGroup\\.groupAddress').val(groupAddress);
			$('#hidden\\.editGroup\\.contactName').val(contactName);
			$('#hidden\\.editGroup\\.contactEmail').val(contactEmail);
			$('#hidden\\.editGroup\\.contactTelNo').val(contactTelNo);
			$('#hidden\\.editGroup\\.contactCellNo').val(contactCellNo);
			$('#hidden\\.editGroup\\.groupNote').val(groupNote);
			$('#hidden\\.editGroup\\.postAcct').val(postAcct);
			$('#hidden\\.editGroup\\.achEdiid').val(achEdiid);
			
			doAjaxSaveGroup();
		});
		
		function doAjaxSaveGroup() {
			$('#doAjaxMethod').attr('name', 'doAjaxSaveGroup');
			
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9007.action'/>",
				async : true,
				type : 'POST',
				data : 	$("#editGroupHiddenForm").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					$("#ajaxErrorMessageDiv").html(data);
					$("#ajaxErrorMessageDiv").dialog({
						title : '<%=UserUtil.getCurrentMenuItemName() %>',
						width : 400,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
								
								if (1==$("#doAjaxSaveGroupResultCode").val()){
									
									
									if (1==$("#continueEditRealAccount").val()){
										var pk = $("#doAjaxSavegroupPk").val();
										$('#editGroup\\.groupPk').val(pk);
										$('#hidden\\.editGroup\\.groupPk').val(pk);
										$("#editRealAccountBtn").show();
										$("#EditPaymentCanceledBtn").show();
										doQueryAction();
									}
									else{
										$("#editGroupDiv").dialog("close");
										doQueryAction();
									}
									
									
									
								}
							}
						}
					});
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
		}
				
		$("#editRealAccountBtn").click(function() {
			var groupPk = $('#editGroup\\.groupPk').val();
			toAjaxEditRealAccountAction(groupPk);				
		});
		
		$("#EditPaymentCanceledBtn").click(function() {
			var groupPk = $('#editGroup\\.groupPk').val();
			toAjaxEditPaymentCanceledAction(groupPk);				
		});
		
		$('#printBtn3').click(function() {
			divPrint('editGroupDiv');
		});
	
		
	});
//-->
</script>
<div id="editGroupFormDiv">
	<stripes:form id="editGroupForm" name="editGroupForm" 
		beanclass="com.feib.soeasy.action.Soez9007ActionBean" method="post" onsubmit="javascript: return false;">
	
	<table id="queryForm">
		<tr>
			<td colspan="4" style="color: #990000">
				<strong>
					<c:choose>
						<c:when test="${null == actionBean.editGroup.groupPk }">帳單業者新增</c:when>
						<c:otherwise>帳單業者修改</c:otherwise>
					</c:choose> 
				</strong>
			</td>
			<stripes:hidden id="editGroup.groupPk" name="editGroup.groupPk" />
		</tr>
		<tr>
			<th>業者代號<span id="mustKeyInStar">**</span></th>
			<td>
				<c:choose>
					<c:when test="${null != actionBean.editGroup.groupPk }"><stripes:text id="editGroup.groupNo" name="editGroup.groupNo" size="12" maxlength="12" readonly="true"/></c:when>
					<c:otherwise><stripes:text id="editGroup.groupNo" name="editGroup.groupNo" size="12" maxlength="12"/></c:otherwise>
				</c:choose>
				
			</td>
			<th>業者類別<span id="mustKeyInStar">**</span></th>
			<td>
				<c:choose>
					<c:when test="${null == actionBean.editGroup.groupPk }">
						<stripes:select id="editGroup.groupType" name="editGroup.groupType">
							<stripes:option value="" label="--請選擇--"/>
							<stripes:option value="2" label="學校"/>
							<stripes:option value="3" label="一般收費"/>
							<stripes:option value="4" label="車貸策略聯盟"/>
						</stripes:select>
					</c:when>
					<c:otherwise>
						<stripes:hidden id="editGroup.groupType" name="editGroup.groupType"/>
						<c:choose>
							<c:when test="${2 == actionBean.editGroup.groupType }">學校</c:when>
							<c:when test="${3 == actionBean.editGroup.groupType }">一般收費</c:when>
							<c:when test="${4 == actionBean.editGroup.groupType }">車貸策略聯盟</c:when>
							<c:otherwise></c:otherwise>
						</c:choose>
					</c:otherwise>
				</c:choose> 
			</td>
			<th>ACH業者代號</th>
			<td >
				<c:choose>
					<c:when test="${null != actionBean.editGroup.achEdiid }"><stripes:text id="editGroup.achEdiid" name="editGroup.achEdiid" size="12" maxlength="12" /></c:when>
					<c:otherwise><stripes:text id="editGroup.achEdiid" name="editGroup.achEdiid" size="12" maxlength="12"/></c:otherwise>
				</c:choose>
				
			</td>	
		</tr>
		<tr>
			<th>業者名稱<span id="mustKeyInStar">**</span></th>
			<td colspan="3">
				<stripes:text id="editGroup.groupName" name="editGroup.groupName" size="40" maxlength="30"/>
			</td>
		</tr>
		<tr>
			<th>主辦銀行<span id="mustKeyInStar">**</span></th>
			<td colspan="3">
				<stripes:text id="editGroup.mainBank" name="editGroup.mainBank" size="40" maxlength="25"/>
				<span><font size="1">ex:遠東銀行台北忠孝分行 (805-0311)</font></span>
			</td>
		</tr>
		<tr>
			<th>地址<span id="mustKeyInStar">**</span></th>
			<td colspan="3">
				<stripes:text id="editGroup.groupAddress" name="editGroup.groupAddress" size="40" maxlength="50"/>
			</td>
		</tr>
		<tr>
			<th>聯絡人<span id="mustKeyInStar">**</span></th>
			<td>
				<stripes:text id="editGroup.contactName" name="editGroup.contactName" size="10" maxlength="10"/>
			</td>
			<th>E-MAIL<span id="mustKeyInStar">**</span></th>
			<td>
				<stripes:text id="editGroup.contactEmail" name="editGroup.contactEmail" size="20" maxlength="40"/>
			</td>
		</tr>
		<tr>
			<th>電話號碼<span id="mustKeyInStar">**</span></th>
			<td>
				<stripes:text id="editGroup.contactTelNo" name="editGroup.contactTelNo" size="20" maxlength="20"/>
			</td>
			<th>手機號碼<span id="mustKeyInStar">**</span></th>
			<td>
				<stripes:text id="editGroup.contactCellNo" name="editGroup.contactCellNo" size="20" maxlength="10"/>
			</td>
		</tr>
		<tr>
		    <th>劃撥帳號</th>
			<td>
				<stripes:text id="editGroup.postAcct" name="editGroup.postAcct" size="10" maxlength="8"/>
			</td>
			<th>備註</th>
			<td colspan="2">
				<stripes:text id="editGroup.groupNote" name="editGroup.groupNote" size="30" maxlength="40"/>
			</td>
		</tr>
		<tr>
			<th>建立者</th>
			<td><c:out value="${actionBean.editGroup.createdBy }"/></td>
			<th>建立時間</th>
			<td><fmt:formatDate value="${actionBean.editGroup.createdDate}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
		</tr>
		<tr>
			<th>修改者</th>
			<td><c:out value="${actionBean.editGroup.updatedBy }"/></td>
			<th>修改時間</th>
			<td><fmt:formatDate value="${actionBean.editGroup.updatedDate}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
		</tr>
		<tr>
			<td colspan="4" class="queryFunction">
				<input type="button" id="doSaveGroupBtn" value="確認" />
			<c:choose>
				<c:when test="${null != actionBean.editGroup.groupPk }">
					<input type="button" id="doDeleteGroupBtn" value="刪除"/>
					<input type="button" id="editRealAccountBtn" value="實體帳戶" />
				</c:when>
				<c:otherwise>
				    <input type="button" id="editRealAccountBtn" value="實體帳戶" style="display: none; "/>
				</c:otherwise>				
			</c:choose>
				<input type="button" id="EditPaymentCanceledBtn" value="銷帳代碼設定" /> 
				<input type="button" id="printBtn3" value="列印" />
				<input type="button" id="cancelEditGroupBtn" value="離開" />
			</td>
		</tr>
	</table>
</stripes:form>
</div>

<div id="editGroupHiddenDiv" style="display: none;">
<stripes:form id="editGroupHiddenForm" name="editGroupHiddenForm" 
	beanclass="com.feib.soeasy.action.Soez9007ActionBean" method="post" onsubmit="javascript: return false;">
	<input id="hidden.editGroup.groupPk" name="editGroup.groupPk" />
	<input id="hidden.editGroup.groupNo" name="editGroup.groupNo" />
	<input id="hidden.editGroup.groupType" name="editGroup.groupType" />
	<input id="hidden.editGroup.groupName" name="editGroup.groupName" />
	<input id="hidden.editGroup.groupAddress" name="editGroup.groupAddress" />
	<input id="hidden.editGroup.contactName" name="editGroup.contactName" />
	<input id="hidden.editGroup.contactEmail" name="editGroup.contactEmail" />
	<input id="hidden.editGroup.contactTelNo" name="editGroup.contactTelNo" />
	<input id="hidden.editGroup.contactCellNo" name="editGroup.contactCellNo" />
	<input id="hidden.editGroup.mainBank" name="editGroup.mainBank" />
	<input id="hidden.editGroup.groupNote" name="editGroup.groupNote" />
	<input id="hidden.editGroup.postAcct" name="editGroup.postAcct" />
	<input id="hidden.editGroup.achEdiid" name="editGroup.achEdiid" />
	<input type="hidden" id="doAjaxMethod" name="doAjaxSaveGroup" />
</stripes:form>
</div>

